const koa = require('koa');
const app = new koa();
const static = require('./applymiddleware/static');
const bodyParser = require('koa-bodyparser');
const router = require('koa-router')();
let PORT = 3000;

app.use(bodyParser());
app.use(router.routes(), router.allowedMethods());
app.use(static('./public'));

router.get('/home', (ctx, next) => {
    const {name, pwd} = ctx.query;
    console.log(name, pwd);
    ctx.body = {
        name,
        pwd
    }
});

router.get('/list', (ctx, next) => {
    const data = ctx.params;
    console.log(data);
    ctx.body = {
        data
    }
})  

router.post('/getList', (ctx, next) => {
    const {name, pwd} = ctx.request.body;
    console.log(name, pwd);
    ctx.body = {
        name, 
        pwd
    }
})

app.listen(PORT, ()=>{ console.log('启动成功，端口：'+PORT); })